package com.dt.dubai.mber.service;

import com.dt.dubai.mber.entity.MberCustomerAddrEntity;
import com.dt.dubai.mber.service.innate.MberCustomerAddrSerInnateAbsImp;
import com.dt.dubai.mber.service.ser.MberCustomerAddrService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MberCustomerAddrServiceImp extends MberCustomerAddrSerInnateAbsImp implements MberCustomerAddrService {

    /*innateServiceStart*/
    @Override
    protected void userSavEntity(MberCustomerAddrEntity inEntity) {

    }

    @Override
    protected void userModEntity(MberCustomerAddrEntity inEntity, MberCustomerAddrEntity upEntity) {
        upEntity.setCustomerRecordId(inEntity.getCustomerRecordId()); // 顾客登录记录ID
        upEntity.setZipCode(inEntity.getZipCode()); // 邮编
        upEntity.setCityProvinceArea(inEntity.getCityProvinceArea()); // 省份城市区
        upEntity.setExpressAddress(inEntity.getExpressAddress()); // 快递地址
        upEntity.setDefaultAddress(inEntity.getDefaultAddress()); // 默认地址标识

    }
    /*innateServiceEnd*/
    /*以上内容请误删除或是移动，系统升级使用，static系统升级覆盖用户修改，用户代码请写入下方*/

    @Override
    public Map<String, Object> findFindListByUserId(Map<String, Object> map, final Long userId){

       return this.mberCustomerAddrMapper.findFindListByUserId(map, userId);
    }


    @Override
    public void updateDefaultAddress(Long newRecordId,Long oldRecordId) {
        MberCustomerAddrEntity newAddrEntity = mberCustomerAddrMapper.selectByPrimaryKey(newRecordId);
        MberCustomerAddrEntity oldAddrEntity = mberCustomerAddrMapper.selectByPrimaryKey(oldRecordId);
        newAddrEntity.setDefaultAddress(true);
        this.modEntity(newAddrEntity,newRecordId);
        oldAddrEntity.setDefaultAddress(false);
        this.modEntity(oldAddrEntity,oldRecordId);
    }

}
